package stringdemo;

public class StringDriver {

    public static void main(String[] args) {

        System.out.println("---定义String工具类-------");
        test01();
        System.out.println();
        System.out.println("-------String工具类中的栈和堆的对等-----------");
        test02();
    }

    /**
     *  String 工具类
     */

    public  static void test01(){

        //定义字符串
        String string = "tianjijdndcdc;sixaisc;sixsjssnncndcn;cjsncjsdns;";


        System.out.println("a;;;"+string.indexOf('a'));  //开始的位置
        System.out.println("a;;;"+string.lastIndexOf('a'));//结束的位置
        System.out.println("   ;;"+string.substring(2,6));//处2到6位置的字符
    }

    /**
     * String 工具类
     * 栈和堆
     */

    public  static  void  test02(){


        String string0 = "小明";//栈中
        String string1 = "小明";//栈中
        String string2 = new String("小明");//堆中
        String string3 = new String("小明");//堆中

        System.out.println("string0 == string1 :"+(string0 == string1));
        System.out.println("string0 == string2 :"+(string0 == string2));
        System.out.println("string2 == string3 :"+(string2 == string3));
    }
}
